<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <link rel="stylesheet"type="text/css"href="css/menu.css">
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
        <title>TTT</title>
    </head>
    <form>
        <body id="body">
            <div id="header">       
            </div>
            <div id="menu">
                <ul id="s">
                    <li><a href="#">HOME</a>
                    </li>
                    <li><a href="#">ABOUT US</a>
                    </li>
                    <li><a href="#">FORUMS</a>
                    </li>
                    <li><a href="#">CONTACT</a>
                    </li>
                    <?php if (isset($_GET["uid"])): ?>
                        <a href="index.php" style="font-size: 18px"><b>LOGOUT</b></a>
                    <?php endif; ?>
                </ul>


            </div>
    </form>
    <div id="page_body">  


        <div class="login">   <table>
                <form method="Post">
                    <tr>
                        <td>Username: </td>
                        <td><input type="text" name="username" id="name"></td>
                    </tr>
                    <tr>
                        <td>Password: </td>
                        <td><input type="password" name="password" id="password"></td>
                    </tr>
                    <tr>      <td>  <input type="submit" name="submit" value="Đăng Nhập"></td></tr>
                </form>
            </table>
        </div> 
        <?php
        require_once 'model/works.php';
        require_once 'model/pagination.php';
        require_once 'model/user.php';


        if (isset($_POST['submit'])) {
            $username = $_POST['username'];
            $password = $_POST['password'];
            $Ok = FALSE;
            $index = -1;
            for ($i = 0; $i < count($users); $i++) {
                if ((strcmp($users[$i]['username'], $username) == 0) &&
                        (strcmp($users[$i]['password'], $password) == 0)) {
                    $Ok = TRUE;
                    $index = $i;
                }
            }
            if ($Ok) {
                header("Location: http://localhost:82/ttthu-web2/index.php?uid=" . $users[$index]['id']);
            } else {
                echo "đăng nhập lại đi bạn :D";
            }
        }

        $works = new works();
        $pagination = new Pagination();

        if (!isset($_GET["page"]))
            $page = 1;
        else
            $page = $_GET["page"];
        $list = $works->select($page);
        $total = $works->count();
        echo $pagination->Display($page, $total, null, "index.php")
        ?>
        <div class="ajax_show">

        </div>
        <table border="1px">
            <tr>
                <td>stt</td>
                <td>name</td>
                <td>posted</td>
                <td>options</td>
                <td>images</td>
            </tr>
            <tr>
                <?php foreach ($list as $item): ?>
                    <td><a><?php echo $item['id'] ?></a></td>
                    <td><a href=<?php echo $item['url']; ?>><?php echo $item['name'] ?></a></td>

                    <td><a><?php $mydate = getdate($item['posted']); ?>
                            <?php echo "$mydate[mday] $mydate[month], $mydate[year]"; ?></a></td>
                 
                        <td>
                            <a href="upload.php?id=<?php echo $item['id']; ?>">edit</a><br>
                            <a href="#" class="ajax_view" id_keyword="<?php echo $item['description']; ?>">View</a><br>
                            <a>delete</a>
                        </td>

                    <td><img src='<?php echo $item['image'] ?>' width="55px"></td>
                </tr>

            <?php endforeach; ?>
        </table>
    </div>
    <div id="conten">       
    </div>
    <div id="sidebar">       
    </div>
    <table id="footer">
        <tr>
            <td><h3>Tran Thi Thu_c12tdt </h3></td>
        </tr>

    </table>
    <script type="text/javascript">
        $(document).ready(function() {
            $(".ajax_view").click(function() {
                id_keyword = $(this).attr('id_keyword');
                url = 'ajax.php?id_keyword=' + id_keyword;
                $.ajax({
                    url: url,
                }).done(function(data) {
                    $('.ajax_show').html(data);
                });
            });
        });
    </script>

</body>
</html>

